package com.xiaoman.httpremote.base;



import com.xiaoman.httpremote.annotation.EnableHttpRemoteUrl;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

public class HttpRemoteRegister implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
        Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(EnableHttpRemoteUrl.class.getName());
        AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(attributes);
        String[] basePackages = null;
        assert annotationAttributes != null;
        basePackages = annotationAttributes.getStringArray("value");
        HttpRemoteClassPathBeanDefinitionScanner scanner = new HttpRemoteClassPathBeanDefinitionScanner(registry, false);
        scanner.doScan(basePackages);
    }

}
